

/**
 * @author Carlos
 * @version 1.0
 * @created 09-oct-2013 05:23:40 p.m.
 */
using System.Xml;
using Imaginarium.XML;
using System;
namespace Imaginarium.stats
{
    public class Elemental: ICloneable
    {

        public float earth { get; set; }
        public float fire { get; set; }
        public float water { get; set; }
        public float wind { get; set; }
        public bool isPercentage { get; set; }

        public Elemental(float fire, float water, float wind, float earth, bool isPercentage)
        {
            this.fire = fire;
            this.water = water;
            this.wind = wind;
            this.earth = earth;
            this.isPercentage = isPercentage;
        }
        public Elemental(float fire, float water, float wind, float earth):
            this(fire,water,wind,earth,true)
        {
            
        }
        public Elemental():
            this(0,0,0,0)
        {

        }

        public Elemental(XmlElement element) {
            this.earth = XmlHelper.getIntByTagname(element, XmlParameters.ELEMENTAL_EARTH);
            this.fire = XmlHelper.getIntByTagname(element, XmlParameters.ELEMENTAL_FIRE);
            this.wind = XmlHelper.getIntByTagname(element, XmlParameters.ELEMENTAL_WIND);
            this.water = XmlHelper.getIntByTagname(element, XmlParameters.ELEMENTAL_WATER);
            this.isPercentage = XmlHelper.getBoolByTagname(element, XmlParameters.ELEMENTAL_IS_PERCENTAGE);
        }
        public override string ToString()
        {
            string ans = "";
            ans += "fire: " + fire + "\n";
            ans += "water: " + water + "\n";
            ans += "wind: " + wind + "\n";
            ans += "earth: " + earth + "\n";
            ans += "isPercentage: " + isPercentage + "\n";
            return ans;
        }
        public static Elemental operator +(Elemental e1, Elemental e2)
        {
            if (e1 == null)
                return e2;
            if (e2 == null)
                return e1;
            Elemental e = new Elemental();
            e.earth = e1.earth + e2.earth;
            e.fire = e1.fire + e2.fire;
            e.water = e1.water + e2.water;
            e.wind = e1.wind + e2.wind;
            return e;
        }
        public static Elemental operator -(Elemental e1, Elemental e2)
        {
            if (e1 == null)
                return e2;
            if (e2 == null)
                return e1;
            Elemental e = new Elemental();
            e.earth = e1.earth - e2.earth;
            e.fire = e1.fire - e2.fire;
            e.water = e1.water - e2.water;
            e.wind = e1.wind - e2.wind;
            return e;
        }

        /**
         * En el caso que e2 sea porcentual, se utiliza este operador.
         * En casos generales, e1 son los ElementalStats basicos del character
         * Esto calcula los ElementalStats final que va a tener el arma/armadura
         */
        public static Elemental operator *(Elemental e1, Elemental e2)
        {
            if (e1 == null || e2 == null)
                return null;
            if (!e2.isPercentage) return null;
            Elemental e = new Elemental();
            e.earth = e1.earth * e2.earth / 100;
            e.fire = e1.fire * e2.fire / 100;
            e.water = e1.water * e2.water / 100;
            e.wind = e1.wind * e2.wind / 100;
            return e;
        }

        /**
         * En caso de multiplicar por escalar
         */
        public static Elemental operator *(Elemental e1, int num)
        {
            if (e1 == null) return null;
            if (e1.isPercentage) return null;
            Elemental e = new Elemental();
            e.earth = e1.earth * num;
            e.fire = e1.fire * num;
            e.water = e1.water * num;
            e.wind = e1.wind * num;
            return e;
        }

        public static Elemental operator *(int num , Elemental e1) {
            if (e1 == null) return null;
            return e1 * num;
        }

        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        #endregion
    }
    
}
